package listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenuItem;

import view.KoalaGlassPane;
import view.MainFrame;
import controller.FilterController;
import controller.LayerController;
import controller.LayeredPaneController;
import controller.MainController;
import controller.SettingsController;

public class MenuListener implements ActionListener {

	public MenuListener() {
		super();
	}

	/**
	 * Catch action from the MenuBar
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		JMenuItem itemSource = (JMenuItem) e.getSource();
		// -- file
		if (itemSource.getName().equals("new")) {
			MainController.newFile();
		}
		if (itemSource.getName().equals("quit")) {
			MainController.closeApplication();
		}
		if (itemSource.getName().equals("save")) {
			MainController.saveFile();
		}
		// -- layer
		if (itemSource.getName().equals("simple_layer")) {
			LayeredPaneController.createAnEmptyLayer();
		}
		if (itemSource.getName().equals("image_layer")) {
			LayeredPaneController.createAnImageLayer();
		}
		if (itemSource.getName().equals("text_layer")) {
			LayeredPaneController.createATextLayer();
		}
		if (itemSource.getName().equals("color_layer")) {
			LayeredPaneController.createAColorLayer();
		}
		if (itemSource.getName().equals("change_opacity")) {
			LayerController.changeOpacity(MainFrame.getInstance().getDrawingPane().getSelectedLayer());
		}
		if (itemSource.getName().equals("brightness_contrast_filter")) {
			FilterController.openBrigthnessContrastFilterDialog();
		}
		if (itemSource.getName().equals("pixel_filter")) {
			FilterController.openPixelFilterDialog();
		}
		if (itemSource.getName().equals("color_filter")) {
			FilterController.openColorFilterDialog();
		}
		if (itemSource.getName().equals("display_grid")) {
			if (KoalaGlassPane.DISPLAY_GRID)
				itemSource.setText("Show grid");
			else
				itemSource.setText("Hide grid");
			SettingsController.changeGridState();
		}
		if (itemSource.getName().equals("parameters")) {
			SettingsController.openParametersDialog();
		}
	}
}
